#Dockerfile to build a pdf2htmlEx image

FROM ubuntu:16.04
MAINTAINER innobase innobase@innobase.cn

#
#Install git and all dependencies
#
RUN set -xe \
    && echo " # Preparing ..." \
    && export DEBIAN_FRONTEND=noninteractive \
    && export SSL_CERT_DIR=/etc/ssl/certs/ \
    && export GIT_SSL_CAPATH=/etc/ssl/certs/ \
    && mv /etc/apt/sources.list /etc/apt/sources.list.bak \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial main\ndeb http://mirrors.aliyun.com/ubuntu/ xenial-updates main\ndeb http://mirrors.aliyun.com/ubuntu/ xenial universe\ndeb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe\ndeb http://mirrors.aliyun.com/ubuntu/ xenial-security main\ndeb http://mirrors.aliyun.com/ubuntu/ xenial-security universe\n'>/etc/apt/sources.list \
    && apt-get update \
    && apt-get install -y  apt-utils \
    && apt-get upgrade -y \
    && apt-get install -qq git cmake autotools-dev libjpeg-dev libtiff5-dev libpng12-dev libgif-dev libxt-dev autoconf automake libtool bzip2 libxml2-dev libuninameslist-dev libspiro-dev python-dev libpango1.0-dev libcairo2-dev chrpath uuid-dev uthash-dev libpoppler-private-dev libpoppler-glib-dev bash \
    && cd / && \
    git clone https://github.com/fontforge/fontforge.git && \
    cd fontforge && \
    ./bootstrap --force && \
    ./configure --without-iconv && \
    make -j 4 && \
    make install && \
    cd / && \
    git clone git://github.com/coolwanglu/pdf2htmlEX.git && \
    cd pdf2htmlEX && \
    export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig && \
    cmake . && make -j 4 && make install && \
    apt-get remove -y autotools-dev libjpeg-dev libtiff5-dev libpng12-dev libgif-dev libxt-dev git cmake autoconf automake libxml2-dev libuninameslist-dev libspiro-dev python-dev libpango1.0-dev libcairo2-dev uuid-dev uthash-dev libpoppler-private-dev libpoppler-glib-dev && \
    apt-get autoremove -y && \
    apt-get install -y libpoppler58 libcairo2 python libpython2.7 libspiro0 libglib2.0-0 libltdl7 libgif7 libjpeg8 libuninameslist0 uuid libtiff5 libpng12-0 libxt6 libpango1.0 && \
    echo "/usr/local/lib" >> /etc/ld.so.conf && ldconfig && \
    rm -rf /var/lib/apt/lists/* /root/.cache && \
    rm -rf /fontforge /libspiro /libuninameslist /pdf2htmlEX


VOLUME /pdf
WORKDIR /pdf

# CMD ["/usr/local/bin/pdf2htmlEX"]
CMD ["/bin/bash"]